#include "common.h"
#include "filter.h"
#include "misc.h"

extern uint16 amp[4];

double amp_his[4];
double uni[4];

void unify(void){
    int i;
    for(i=0; i<4; ++i){
        uni[i]=MIN(uni[i], AMP_UNI_MAX);
        uni[i]=MAX(uni[i], AMP_UNI_MIN);
        uni[i]=(uni[i]-AMP_UNI_MIN)/AMP_UNI_MAX;
    }
}

void ewma(void){
    int i;
    const double e=0.6;
    for(i=0; i<4; ++i){
        amp_his[i]=e*amp[i]+(1-e)*amp_his[i];
        uni[i]=amp_his[i];
        amp[i]=(uint16)uni[i];
    }
}

void amp_process(void){
    ewma();
    unify();
}
